package com.hy;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

import javax.sql.DataSource;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * author: Mr.Du
 * Date: 2022/9/5
 * Time: 13:47
 */
//@Configuration这是一个配置类
@Configuration
@ComponentScan("com.hy")
@PropertySource({"classpath:jdbc.properties"})
//要想aop生效，必须加入下面注解，自动开启代理
@EnableAspectJAutoProxy
public class SpringConfig {
    
    @Value("${jdbc.driver}")
    private String driverClassName;
    
    @Value("${jdbc.url}")
    private String url;
    
    @Value("${jdbc.username}")
    private String username;
    
    @Value("${jdbc.password}")
    private String password;
    
    @Bean("dataSource")
    public DataSource createDataSource(){
        
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
